package com.gogowan.agroenterprise.widget.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.gogowan.agroenterprise.R;
import com.gogowan.agroenterprise.model.IntMaterial;

/**
 * 仓储list adapter
 * 
 * @author tjh 2017-01-13
 *
 */
public class IntMaterialListViewAdapter extends BaseAdapter {
	private Context mContext;
	private List<IntMaterial> intMaterialList;

	public IntMaterialListViewAdapter(Context mContext,
			List<IntMaterial> intMaterialList) {
		this.mContext = mContext;
		this.intMaterialList = intMaterialList;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return intMaterialList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return intMaterialList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewHolder = null;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.activity_int_material_listview_item, null);
			viewHolder.cpmcText = (TextView) convertView
					.findViewById(R.id.int_material_listview_item_cpmc_text);
			viewHolder.slText = (TextView) convertView
					.findViewById(R.id.int_material_listview_item_cpsl_text);
			viewHolder.zlText = (TextView) convertView
					.findViewById(R.id.int_material_listview_item_cpzl_text);
			viewHolder.hwmcText = (TextView) convertView
					.findViewById(R.id.int_material_listview_item_hwmc_text);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		viewHolder.cpmcText.setText(intMaterialList.get(position)
				.getMaterialName());
		viewHolder.slText.setText(intMaterialList.get(position).getCount());
		viewHolder.zlText.setText(intMaterialList.get(position).getWeight());
		viewHolder.hwmcText.setText(intMaterialList.get(position)
				.getStoreName());

		return convertView;
	}

	class ViewHolder {
		TextView cpmcText;
		TextView slText;
		TextView zlText;
		TextView hwmcText;
	}
}
